
'use strict';
let Util = {
    baseUrl:'http://10.5.102.165:10081',//测试
    joinSplit:'@_____@',
    //时间
    getDate: () => {
        var d = new Date();
        return d.getDate();
    },
    getMonth:
        () => {
            var d = new Date();
            return d.getMonth() + 1;
        }
    ,
    getYear:
        () => {
            var d = new Date();
            return d.getFullYear();
        }
    ,
    getFullYear:
        () => {
            var d = new Date();
            var str = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();
            return str;
        }
    ,
    /**
     * http get 请求简单封装
     * @param url 请求的URL
     * @param successCallback 请求成功回调
     * @param failCallback 请求失败回调
     */
    get: (url, successCallback, failCallback) => {
        fetch(url)
            .then((response) => response.text())
            .then((responseText) => {
                let resultJson = JSON.parse(responseText);
                successCallback(resultJson);
            })
            .catch((err) => {
                failCallback(err);
            });
    },
    post: (url, data,successCallback, failCallback) => {
        let fetchOptions = {
            method: 'POST',
            headers : {
             'Content-Type': 'application/json;charset=UTF-8',
           },
            body: JSON.stringify(data)
        };

        fetch(url, fetchOptions)
            .then((response) => response.text())
            .then((responseText) => {
                let result = JSON.parse(responseText);
                successCallback(result);
            })
            .catch((err) => {
                failCallback(err);
            });
    }
};

export default Util;